package com.wjl.shop.controller;

import com.wjl.shop.entity.StockOrder;
import com.wjl.shop.service.StockOrderService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 备货订单表(StockOrder)表控制层
 *
 * @author makejava
 * @since 2021-10-06 14:43:22
 */
@RestController
@RequestMapping("stockOrder")
@CrossOrigin
public class StockOrderController {
    /**
     * 服务对象
     */
    @Resource
    private StockOrderService stockOrderService;
    @GetMapping("selectOrder")
    public Map<String,Object> selectOrder(StockOrder stockOrder){
        return stockOrderService.selectOrder(stockOrder);
    }
    @GetMapping("updateState")
    public Map<String,Object> updateState(StockOrder stockOrder){
        return stockOrderService.update(stockOrder);
    }


    /**
     * 提交订单
     * @param request
     * @return
     */
    @RequestMapping("/subOrder")
    public Map<String,Object> subOrder(HttpServletRequest request){
        return stockOrderService.addOrder(request);
    }

    /**
     * 保存订单
     * @param request
     * @return
     */
    @RequestMapping("saveOrder")
    public Map<String,Object> saveOrder(HttpServletRequest request){
        return stockOrderService.saveOrder(request);
    }

    @PostMapping("sumStockOrder")
    @CrossOrigin
    public Map<String,Object> sumStockOrder(@RequestBody List<String> stockOrderCodes){
        return stockOrderService.sumOrdersByCodes(stockOrderCodes);
    }
    /**
     * 上传附件
     * */
    @PostMapping("updateFile")
    public Map<String,Object> updateFile(StockOrder stockOrder, MultipartFile file) throws IOException {
        return stockOrderService.FileUpdate(stockOrder,file);
    }

    /**
     * 待审核备货订单列表查询
     * @param stockOrder
     * @return
     */
    @GetMapping("serchInfo")
    public Map<String,Object> serchInfo(StockOrder stockOrder){
       return  this.stockOrderService.serchInfo(stockOrder);
    }
    /**
     * 审核信息更改
     * @param list
     * @return
     */
    @GetMapping("updateInfo")
    public  Map<String,Object> updateInfo( @RequestParam(value = "list" ,required=false)List<String> list,StockOrder stockOrder){
        return  this.stockOrderService.updateInfo(list,stockOrder);
    }

    /**
     * 复审信息
     * @param stockOrder
     * @return
     */
    @GetMapping("review")
    public Map<String,Object> review(StockOrder stockOrder){
        return this.stockOrderService.review(stockOrder);
    }

    /**
     * 审核不通过理由
     * @param stockOrder
     * @return
     */
    @GetMapping("updatenot")
    public Map<String,Object> updatenot(StockOrder stockOrder){
        return this.stockOrderService.updatenot(stockOrder);
    }
    /**
     * 提交订单
     * @param orderCodes
     * @return
     * */
    @GetMapping("commitOrder")
    public Map<String,Object> commitOrder(@RequestParam(value = "list" ,required=false)List<String> orderCodes){
        return stockOrderService.commitOrder(orderCodes);
    }
    /**
     * 取消订单
     * */
    @GetMapping("cancelOrder")
    public Map<String,Object> canCel(@RequestParam(value = "list" ,required=false)List<String> list){
        return stockOrderService.canCel(list);
    }
    /**
     * 修改订单
     * */
    @GetMapping("modifyOrder")
    public Map<String,Object> modifyOrder(StockOrder stockOrder){
        return stockOrderService.modifyOrder(stockOrder);
    }
}
